package com.ly.algorithm.offerpointer;

/**
 * @Classname Offer05
 * @Description
 *
 * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 * 示例 1：
 *
 * 输入：s = "We are happy."
 * 输出："We%20are%20happy."
 *
 * @Date 2020/12/30 19:46
 * @Author 冷心影翼
 */
public class Offer05 {

    public static void main(String[] args) {
        Solution05 solution05 = new Solution05();
        System.out.println(solution05.replaceSpace("We are happy."));
    }
}

class Solution05 {
    public String replaceSpace(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)!=' ') {
                sb.append(s.charAt(i));
            }else {
                sb.append("%20");
            }
        }
        return sb.toString();
    }
}
